//
//  WPRightManageInvalidHeadView.m
//  ZhongChouPingTai
//
//  Created by WeiPan on 16/4/8.
//  Copyright © 2016年 WPJoe. All rights reserved.
//

#import "WPRightManageInvalidHeadView.h"
@interface WPRightManageInvalidHeadView ()

@property (nonatomic, strong) UILabel * titleLabel;/**< 标题 */
@property (nonatomic, strong) UIButton * deleteBtn;/**< 垃圾桶删除 */
@property (nonatomic, strong) UIImageView * activeImageView;/**< 活动海报 */
@property (nonatomic, strong) UITextField * moneyTextField;/**< 金额展示 */
@property (nonatomic, strong) UITextField * numTextField;/**< 数量展示 */
@property (nonatomic, strong) UITextField * addressTextField;/**< 地址展示 */
@property (nonatomic, strong) UITextField * usableTimeTextField;/**< 有效期 */
@property (nonatomic, strong) UIView * titlesView;/**< cell参数说明 */
@property (nonatomic, strong) WPTransRightManageHeadModel * headModel;
- (void)initializeAppearance;/**< 一般界面初始化 */
@end
@implementation WPRightManageInvalidHeadView
- (instancetype)initWithHeadModel:(WPTransRightManageHeadModel *)model {
    if (self = [super init]) {
        _headModel = model;
        self.frame = CGRectMake(0, 0, 300*DHFlexibleHorizontalMutiplier(), 140*DHFlexibleHorizontalMutiplier());
        [self initializeAppearance];
    }
    return self;
}
#pragma mark - init
- (void)initializeAppearance {
    self.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.titleLabel];
    [self addSubview:self.deleteBtn];
    UIView * line = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_titleLabel.frame), 300*DHFlexibleHorizontalMutiplier(), 1)];
    line.backgroundColor = COLOR_RGB(241, 241, 241, 1);
    [self addSubview:line];
    [self addSubview:self.activeImageView];
//    [self addSubview:self.moneyTextField];
    [self addSubview:self.numTextField];
    [self addSubview:self.addressTextField];
    [self addSubview:self.usableTimeTextField];
    [self addDottedLine];
    [self addSubview:self.titlesView];
    [self configTitleLabel];
}
#pragma mark - responds events
- (void)respondsToSpreadBtn:(UIButton *)sender {
    
}

#pragma mark - 画虚线
- (void)addDottedLine {
    UIBezierPath * path = [UIBezierPath bezierPath];
    CAShapeLayer * layer = [CAShapeLayer layer];
    layer.frame = self.bounds;
    layer.fillColor = [UIColor clearColor].CGColor;
    [layer setLineWidth:1];
    [path moveToPoint:CGPointMake(30*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.usableTimeTextField.frame)+10*DHFlexibleHorizontalMutiplier())];
    [path addLineToPoint:CGPointMake(260*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.usableTimeTextField.frame)+10*DHFlexibleHorizontalMutiplier())];
    [layer setLineDashPattern:[NSArray arrayWithObjects:@(5), @(5), nil]];
    layer.path = path.CGPath;
    layer.backgroundColor = [UIColor clearColor].CGColor;
    layer.strokeColor = COLOR_RGB(231, 231, 231, 1).CGColor; /**< 画笔颜色 */
    [self.layer addSublayer:layer];
}
- (void)configTitleLabel {
    NSArray * titles = @[@"位置", @"价格", @"状态", @"转让价"];
    for (int i = 0; i < titles.count; i++) {
        UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake((10+i%4*70)*DHFlexibleHorizontalMutiplier(), 0, 70*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier())];
        lab.font = [UIFont systemFontOfSize:12*DHFlexibleHorizontalMutiplier()];
        lab.text = titles[i];
        lab.textAlignment = NSTextAlignmentCenter;
        [self.titlesView addSubview:lab];
    }
}
- (NSString *)configEndDate {
    NSDate * date = [NSDate dateWithTimeIntervalSince1970:[_headModel.endDate doubleValue]/1000];
    NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
    formatter.dateFormat = @"yyyyMMdd";
    return [NSString stringWithFormat:@"当前至%@",[formatter stringFromDate:date]];
}
#pragma mark - getter
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(20*DHFlexibleHorizontalMutiplier(), 0, 260*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier())];
            lab.font = [UIFont systemFontOfSize:13*DHFlexibleHorizontalMutiplier()];
            lab.text = _headModel.name;
            lab;
        });
    }
    return _titleLabel;
}
- (UIButton *)deleteBtn {
    if (!_deleteBtn) {
        _deleteBtn = ({
            UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(285*DHFlexibleHorizontalMutiplier(), 7*DHFlexibleHorizontalMutiplier(), 15*DHFlexibleHorizontalMutiplier(), 16*DHFlexibleHorizontalMutiplier());
            [btn setImage:IMAGE_NAME(@"ljt.png") forState:UIControlStateNormal];
            btn;
            
        });
    }
    return _deleteBtn;
}
- (UIImageView *)activeImageView {
    if (!_activeImageView) {
        _activeImageView = ({
            UIImageView * view = [[UIImageView alloc]initWithFrame:CGRectMake(5*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.titleLabel.frame)+10*DHFlexibleHorizontalMutiplier(), 75*DHFlexibleHorizontalMutiplier(), 75*DHFlexibleHorizontalMutiplier())];
            view.layer.cornerRadius = 5*DHFlexibleHorizontalMutiplier();
            view.layer.masksToBounds = YES;
            view.image = IMAGE_NAME(@"XIAOXRAIN");
            view;
        });
    }
    return _activeImageView;
}
- (UITextField *)moneyTextField {
    if (!_moneyTextField) {
        _moneyTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.activeImageView.frame)+10*DHFlexibleHorizontalMutiplier(), CGRectGetMinY(self.activeImageView.frame), 200, 20*DHFlexibleHorizontalMutiplier())];
            text.leftViewMode = UITextFieldViewModeAlways;
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 44*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier())];
            lab.textColor = COLOR_RGB(153, 153, 153, 1);
            lab.font = [UIFont systemFontOfSize:11*DHFlexibleHorizontalMutiplier()];
            lab.text = @"金额：¥";
            text.leftView = lab;
            text.userInteractionEnabled = NO;
            text.font = [UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
            text.textColor = COLOR_RGB(234, 27, 47, 1);
            text;
        });
    }
    return _moneyTextField;
}
- (UITextField *)numTextField {
    if (!_numTextField) {
        _numTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMinX(self.moneyTextField.frame), CGRectGetMaxY(self.moneyTextField.frame), 200, 20*DHFlexibleHorizontalMutiplier())];
            text.leftViewMode = UITextFieldViewModeAlways;
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 44*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier())];
            lab.textColor = COLOR_RGB(153, 153, 153, 1);
            lab.font = [UIFont systemFontOfSize:11*DHFlexibleHorizontalMutiplier()];
            lab.text = @"数量：";
            text.leftView = lab;
            text.userInteractionEnabled = NO;
            text.font = [UIFont systemFontOfSize:11*DHFlexibleHorizontalMutiplier()];
            text.textColor = COLOR_RGB(66, 66, 66, 1);
            text.text = [NSString stringWithFormat:@"%@", _headModel.totol];
            text;
        });
    }
    return _numTextField;
}
- (UITextField *)addressTextField {
    if (!_addressTextField) {
        _addressTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMinX(self.numTextField.frame), CGRectGetMaxY(self.numTextField.frame), 200, 20*DHFlexibleHorizontalMutiplier())];
            text.leftViewMode = UITextFieldViewModeAlways;
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 44*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier())];
            lab.textColor = COLOR_RGB(153, 153, 153, 1);
            lab.font = [UIFont systemFontOfSize:11*DHFlexibleHorizontalMutiplier()];
            lab.text = @"地址：";
            text.leftView = lab;
            text.userInteractionEnabled = NO;
            text.font = [UIFont systemFontOfSize:11*DHFlexibleHorizontalMutiplier()];
            text.textColor = COLOR_RGB(66, 66, 66, 1);
//            text.text = _headModel.
            text;
        });
    }
    return _addressTextField;
}
- (UITextField *)usableTimeTextField {
    if (!_usableTimeTextField) {
        _usableTimeTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMinX(self.moneyTextField.frame), CGRectGetMaxY(self.addressTextField.frame), 200, 20*DHFlexibleHorizontalMutiplier())];
            text.leftViewMode = UITextFieldViewModeAlways;
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 44*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier())];
            lab.textColor = COLOR_RGB(153, 153, 153, 1);
            lab.font = [UIFont systemFontOfSize:11*DHFlexibleHorizontalMutiplier()];
            lab.text = @"有效期：";
            text.leftView = lab;
            text.userInteractionEnabled = NO;
            text.font = [UIFont systemFontOfSize:11*DHFlexibleHorizontalMutiplier()];
            text.textColor = COLOR_RGB(66, 66, 66, 1);
            text.text = [self configEndDate];
            text;
        });
    }
    return _usableTimeTextField;
}
- (UIView *)titlesView {
    if (!_titlesView) {
        _titlesView = ({
            UIView * view = [[UIView alloc]initWithFrame:CGRectMake(5*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.usableTimeTextField.frame)+25*DHFlexibleHorizontalMutiplier(), 290*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier())];
            view.backgroundColor = COLOR_RGB(241, 241, 241, 1);
            view;
        });
    }
    return _titlesView;
}

@end
